<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>赠品小案例</title>
  <style>
    .tag {
      display: block;
    }
  </style>
</head>

<body>
  <p class="name">
    <!-- 
      <span class="tag">【赠品】xxx</span> 
    -->
  </p>
  <script>
    // ============================== 赠品小案例 ==============================
    const nameP = document.querySelector('.name')
    
    const gift = '50g茶叶,清洗球'

    // 具体步骤：
    // const arr = gift.split(',')
    // const arr1 = arr.map(function (ele) {
    //   return `
    // <span class="tag">【赠品】${ele}</span> 
    //   `
    // })
    // document.querySelector('.name').innerHTML = arr1.join('')
    
    // 改造为箭头函数的写法
    document.querySelector('.name').innerHTML = gift.split(',').map( (ele) =>` <span class="tag">【赠品】${ele}</span> `).join('')
     
   
      
    
  </script>
</body>

</html>